//
//  HDCheckInfoView.m
//  HDecoration
//
//  Created by 曹群 on 15/8/15.
//  Copyright (c) 2015年 HDecoration. All rights reserved.
//

#import "HDCheckInfoView.h"
@interface HDCheckInfoView ()
@property(nonatomic,strong)UIImageView *backgroundImage;
@property(nonatomic,strong)UIImageView *photo;
@property(nonatomic,strong)UIButton *nextStepBtn;
@end

@implementation HDCheckInfoView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.backgroundImage];
        [self.backgroundImage addSubview:self.photo];
        [self initLabels];
        [self.backgroundImage addSubview:self.nextStepBtn];
        self.contentSize = CGSizeMake(self.width, self.backgroundImage.height+10);
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
        [self addGestureRecognizer:tapGesture];
    }
    return self;
}

- (void)setRegisterInfo:(HDRegisterInfo *)registerInfo
{
    _registerInfo = registerInfo;
    UILabel *nameLabel = (UILabel *)[self viewWithTag:100];
    nameLabel.text = _registerInfo.name;
    UILabel *identityCardLabel = (UILabel *)[self viewWithTag:101];
    identityCardLabel.text = _registerInfo.identityCardId;
    UILabel *driveCardLabel = (UILabel *)[self viewWithTag:102];
    driveCardLabel.text = _registerInfo.driveCardId;
    UILabel *phoneNumberLabel = (UILabel *)[self viewWithTag:103];
    phoneNumberLabel.text = _registerInfo.phoneNumber;
     _photo.image = self.registerInfo.avatarImg;
}

- (void)initLabels
{
    NSArray *titleArr = @[@"您的姓名",@"身份证号",@"准驾证号",@"手机号码"];
    for (int i=0; i<4; i++) {
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, self.photo.bottom+30*i, 80, 30)];
        titleLabel.font = [UIFont systemFontOfSize:13];
        titleLabel.textColor = [UIColor hexStringToColor:@"#888888"];
        titleLabel.text = titleArr[i];
        UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(titleLabel.right+10, self.photo.bottom+30*i, self.backgroundImage.width-170, 30)];
        contentLabel.font = [UIFont systemFontOfSize:13];
        contentLabel.textColor = [UIColor hexStringToColor:@"#888888"];
        contentLabel.tag = 100+i;
        [self.backgroundImage addSubview:titleLabel];
        [self.backgroundImage addSubview:contentLabel];
    }
    UILabel *tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, self.photo.bottom+170, self.backgroundImage.width-80, 20)];
    tipLabel.font = [UIFont systemFontOfSize:13];
    tipLabel.textColor = [UIColor hexStringToColor:@"#888888"];
    NSString *tipStr = @"请确认上述信息，客服人员将根据您的信息，进行资料审核";
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:tipStr];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.alignment = NSTextAlignmentLeft;
    paragraphStyle.lineSpacing = 10;
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, tipStr.length)];
    tipLabel.numberOfLines = 0;
    tipLabel.attributedText = attributedString;
    [tipLabel sizeToFit];
    [self.backgroundImage addSubview:tipLabel];
}

#pragma mark - actions
- (void)tapAction
{
    [self.superview endEditing:YES];
}

- (void)nextStepAction:(UIButton *)sender
{
    if ([self.delegate respondsToSelector:@selector(nextStepAction:)]) {
        [self.delegate performSelector:@selector(nextStepAction:) withObject:nil];
    }
}

#pragma mark - getters
- (UIImageView *)backgroundImage
{
    if (!_backgroundImage) {
        _backgroundImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 5, APPFRAME.size.width-20, (APPFRAME.size.width-20)*900/600.0)];
        UIImage *image = [UIImage imageNamed:@"填写资料背景图"];
        image = [image stretchableImageWithLeftCapWidth:0 topCapHeight:_backgroundImage.height-10];
        _backgroundImage.image = image;
        _backgroundImage.layer.masksToBounds = YES;
        _backgroundImage.userInteractionEnabled = YES;
    }
    return _backgroundImage;
}

- (UIImageView *)photo
{
    if (!_photo) {
        _photo = [[UIImageView alloc] initWithFrame:CGRectMake((self.backgroundImage.width-76)/2.0, APPFRAME.size.width/3.0-55, 76, 76)];
        _photo.layer.cornerRadius = 38;
        _photo.clipsToBounds = YES;
        _photo.layer.masksToBounds = YES;
        _photo.layer.borderColor = [UIColor whiteColor].CGColor;
        _photo.layer.borderWidth = 5;
        _photo.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _photo;
}

- (UIButton *)nextStepBtn
{
    if (!_nextStepBtn) {
        _nextStepBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _nextStepBtn.frame = CGRectMake(10, self.backgroundImage.height-90, self.backgroundImage.width-20, 44);
        [_nextStepBtn setBackgroundImage:[UIImage imageNamed:@"登录"] forState:UIControlStateNormal];
        [_nextStepBtn setTitle:@"下一步" forState:UIControlStateNormal];
        _nextStepBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [_nextStepBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_nextStepBtn addTarget:self action:@selector(nextStepAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _nextStepBtn;
}

@end
